/**
 * @file
 * @author Ivan Babushkin (jogrms@gmail.com)
 * @date 15.06.2010
 */

#include <toolbutton.h>

ToolButton::ToolButton(QWidget *parent) :QToolButton(parent) {
	finishedPaletteOk = palette();
	finishedPaletteNOk = palette();
	startedPalette = palette();
	progressPalette = palette();
	finishedTextOk = ":)";
	finishedTextNOk = ":(";
	startedText = "+";
	startedPalette.setColor(QPalette::Button, QColor(255, 128, 0));
	progressPalette.setColor(QPalette::Button, QColor(255, 255, 0));
	finishedPaletteOk.setColor(QPalette::Button, QColor(0, 255, 0));
	finishedPaletteNOk.setColor(QPalette::Button, QColor(255, 0, 0));

	resize(20, 20);
}

ToolButton::~ToolButton() {
}

void ToolButton::applySettings(struct QOSettings *settings) {
}

void ToolButton::turnStarted() {
	setPalette(startedPalette);
	setText(startedText);
	show();
}

void ToolButton::turnProgress(int progress) {
	setPalette(progressPalette);
	QString str;
	str.setNum(progress);
	setText(str);
	if ((progress > 0) && (progress < 100)) {
		show();
	}
	else  {
		hide();
	}
}

void ToolButton::turnFinished(bool ok) {

	if (ok) {
		setPalette(finishedPaletteOk);
		setText(finishedTextOk);
		hide();
	}
	else {
		setPalette(finishedPaletteNOk);
		setText(finishedTextNOk);
		show();
	}
}
